package sdwan_data

import (
	"github.com/sirupsen/logrus"
	"smart-sensor-cloud/internal/model"
	"smart-sensor-cloud/internal/nitro"
)

var (
	client *nitro.Client
)

func InitHttpClient() {
	//client = nitro.NewClient("https://bk37672730.qicp.vip:29564")
	client = nitro.NewClient()
	Login2GetCookie()
}

func Login2GetCookie() {

	hosts, err := model.GetAllHost()
	if err != nil {
		return
	}

	for _, host := range hosts {
		err := client.Login2Nitro(
			host.IP,
			host.Port,
			&nitro.LoginReq{
				Login: nitro.LoginBase{
					UserName: host.Username,
					PassWord: host.Password,
				},
			})
		if err != nil {
			logrus.Error(err)
		} else {
			logrus.Info("调用Nitro Login API，更新Cookie成功")
		}
	}
}
